import axios from 'axios';

axios.defaults.withCredentials = true; //允许跨域携带cookie信息
// 登录请求方法
const loginreq = (method, url, params) => {

  // console.log(document.cookie.split(';')[2].substr(11));
		// let session=document.cookie.split(';')[2].substr(11);
		// params.token = params.username;
		// console.log(5555,params);
  return axios({
    method: method,
    url: "https://apiorder.wzq0307.com/" + url, //https://apiorder.wzq0307.com/
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      // 'Cookie': document.cookie //cookie信息
    },
    data: params,
    traditional: true,
    transformRequest: [
      function(data) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) +
            '=' +
            encodeURIComponent(data[it]) +
            '&'
        }
        return ret
      }
    ]
  }).then(res => res.data);
};

// 通用公用方法
const req = (method, url, params) => {
  return axios({
    method: method,
    url: "https://apiorder.wzq0307.com/" + url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      // token: localStorage.getItem('logintoken')
    },
    data: params,
    traditional: true,
    transformRequest: [
      function(data) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) +
            '=' +
            encodeURIComponent(data[it]) +
            '&'
        }
        return ret
      }
    ]
  }).then(res => res.data);
};

export {
  loginreq,
  req,
}
